package com.zcm.modules.cxf.web;

import com.zcm.common.config.Constant;
import com.zcm.common.utils.DateUtils;
import com.zcm.modules.cxf.entity.HeaderEntity;
import com.zcm.modules.cxf.entity.ResultResponse;
import com.zcm.modules.cxf.entity.ReturnResponse;
import com.zcm.modules.cxf.services.Duoduo;
import com.zcm.modules.cxf.utils.RSAUtils;
import com.zcm.modules.cxf.utils.WebServiceHeaderUtil;
import com.zcm.modules.zhaocai.entity.Dadata;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.UUID;

@Controller
@RequestMapping(value = "${frontPath}/kanpan")
public class KanpanController {

	@Autowired
	private Duoduo duoduo;

	@ModelAttribute
	public HeaderEntity initHeader(HttpServletRequest request) {
		String sessionId = request.getHeader(Constant.SESSION_ID);

		HeaderEntity header = new HeaderEntity();
		header.setSessionId(sessionId);
		header.setTime(DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss.SSS"));
		header.setId(UUID.randomUUID().toString());
		header.setCode(WebServiceHeaderUtil.createCode(header.getId(), header.getTime()));
		return header;
	}
	@ResponseBody
	@RequestMapping("/login")
	public ReturnResponse login(String loginName, String plainPassword) {
		return new ReturnResponse(duoduo.login(loginName, plainPassword));
	}

	@ResponseBody
	@RequestMapping("/login2")
	public com.zcm.modules.cxf.entity.LoginResponse login2(String loginName, String password) throws Exception {
		String decrypPassword = RSAUtils.decryptToStr(password, Constant.PRIVATE_KEY);
		return duoduo.login(loginName, decrypPassword);
	}

	@ResponseBody
	@RequestMapping("/logout")
	public ReturnResponse logout(@ModelAttribute HeaderEntity header) {
		return new ReturnResponse(duoduo.logout(header));
	}

	@ResponseBody
	@RequestMapping("/dddata")
	public ReturnResponse dddata(@ModelAttribute HeaderEntity header, String day) {
		Dadata dddata = duoduo.dddata(header,day);
		return new ReturnResponse(dddata);
	}

	@ResponseBody
	@RequestMapping("/register")
	public ResultResponse register(@ModelAttribute HeaderEntity header, String loginName,String password,String mobile,String smgcode) {
		return new ResultResponse(duoduo.register(header,loginName,password,mobile,smgcode));

	}

	@ResponseBody
	@RequestMapping("/forget_pwd")
	public ResultResponse forgetPwd(@ModelAttribute HeaderEntity header, String loginName,String password,String mobile,String smgcode) {
		return new ResultResponse(duoduo.forget_pwd(header,loginName,password,mobile,smgcode));
	}

	@ResponseBody
	@RequestMapping("/forget_msg_code")
	public ResultResponse forgetMsgCode(@ModelAttribute HeaderEntity header, String loginName, String mobile) {
		return new ResultResponse(duoduo.forget_msg_code(header,loginName,mobile));
	}

	@ResponseBody
	@RequestMapping("/ls_article")
	public ReturnResponse lsArticle(@ModelAttribute HeaderEntity header, Integer pageSize,Integer pageNo) {
		return new ReturnResponse(duoduo.ls_article(header,pageSize,pageNo));
	}

	@ResponseBody
	@RequestMapping("/show_article")
	public ReturnResponse showArticle(@ModelAttribute HeaderEntity header, String id) {
		return new ReturnResponse(duoduo.show_atricle(header,id));
	}

	@ResponseBody
	@RequestMapping("/ddqsdx")
	public ReturnResponse ddqsdx(@ModelAttribute HeaderEntity header, String day) {
		return new ReturnResponse(duoduo.ddqsdx(header,day));
	}

	@ResponseBody
	@RequestMapping("/nbg_baseData")
	public ResultResponse nbgBaseData(@ModelAttribute HeaderEntity header, String day) {
		return new ResultResponse(duoduo.nbg_baseData(header,day));
	}

	@ResponseBody
	@RequestMapping("/nbg_beixuan")
	public ResultResponse nbgBeixuan(@ModelAttribute HeaderEntity header, String day) {
		return new ResultResponse(duoduo.nbg_beixuan(header,day));
	}

	@ResponseBody
	@RequestMapping("/nbg_fengko")
	public ResultResponse nbgFengko(@ModelAttribute HeaderEntity header, String day) {
		return new ResultResponse(duoduo.nbg_fengko(header,day));
	}

	@ResponseBody
	@RequestMapping("/nbg_fengkoDetail")
	public ResultResponse nbgFengkoDetail(@ModelAttribute HeaderEntity header, String fengkoId) {
		return new ResultResponse(duoduo.nbg_fengkoDetail(header,fengkoId));
	}

	@ResponseBody
	@RequestMapping("/nbg_juechechi")
	public ResultResponse nbgJuechechi(@ModelAttribute HeaderEntity header, String day) {
		return new ResultResponse( duoduo.nbg_juechechi( header,day));
	}

	@ResponseBody
	@RequestMapping("/nbg_ltyaogu")
	public ResultResponse nbgLtyaogu(@ModelAttribute HeaderEntity header,String day) {
		return new ResultResponse(duoduo.nbg_ltyaogu(header,day));
	}

	@ResponseBody
	@RequestMapping("/nbg_zujichi")
	public ResultResponse nbgZujichi(@ModelAttribute HeaderEntity header, String day) {
		return new ResultResponse(duoduo.nbg_zujichi(header,day));
	}

	@ResponseBody
	@RequestMapping("/xgb_ggxx")
	public ResultResponse xgbGgxx(@ModelAttribute HeaderEntity header,String symbol) {
		return new ResultResponse(duoduo.xgb_ggxx(header,symbol));
	}

}
